package com.gh.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gh.common.result.R;
import com.gh.entity.Borrower;
import com.gh.service.BorrowerService;
import com.gh.vo.BorrowerApprovalVo;
import com.gh.vo.BorrowerDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author Eric
 * @Date 2021/10/8 22:49
 * @Version 1.0
 */
@Api(tags = "借款人管理")
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource
    private BorrowerService borrowerService;

    @ApiOperation(value = "获取借款人分页列表")
    @GetMapping("listPage/{page}/{limit}")
    public R listPage(@ApiParam(value = "查询对象", required = false)
                      @RequestParam String keyword,
                      @ApiParam(value = "当前页码", required = true)
                      @PathVariable Long page,
                      @ApiParam(value = "每页记录数", required = true)
                      @PathVariable Long limit) {
        Page<Borrower> pageParam = new Page<>(page, limit);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam, keyword);
        return R.ok().data("pageModel", pageModel);
    }

    @ApiOperation(value = "获取借款人信息")
    @GetMapping("show/{id}")
    public R show(@ApiParam(value = "借款人id", required = true)
                  @PathVariable Long id) {
        BorrowerDetailVo borrowerDetailVo = borrowerService.getBorrowerDetailVoById(id);
        return R.ok().data("borrowerDetailVo",borrowerDetailVo);
    }

    @ApiOperation(value = "借款人额度审批")
    @PostMapping("approval")
    public R approval(@RequestBody BorrowerApprovalVo borrowerApprovalVo){
        borrowerService.approval(borrowerApprovalVo);
        return R.ok().message("审批完成");
    }
}
